package main

import (
	"andals/gobox/shell"
	"dockerbox/conf"
	"dockerbox/pkg/misc"
	"flag"
	"fmt"
	"os"
)

const ALL_CONTAINER = "all"

func main() {
	defer func() {
		err := recover()
		if err != nil {
			fmt.Println(err)
		}
	}()

	var dconfPath string
	misc.SetCommonFlag(&dconfPath)
	flag.Parse()

	if flag.NArg() < 1 {
		panic("Usage: " + os.Args[0] + " cname/" + ALL_CONTAINER)
	}

	conf.Init(dconfPath)

	key := flag.Arg(0)
	if key == ALL_CONTAINER {
		for k, cconf := range conf.GetAllContainerConf() {
			startSingle(k, cconf)
		}
	} else {
		cconf := conf.GetContainerConf(key)
		startSingle(key, cconf)
	}
}

func startSingle(key string, cconf *conf.Cconf) {
	fmt.Println("Start " + key)

	cmd := "docker start " + cconf.ContainerName
	result := shell.RunCmd(cmd)

	fmt.Println(result.Output)
}
